/*
* @Author: liqs
* @Date:   2021/10/25 11:28
 */
package postgis

import (
	"database/sql"
	"fmt"
	"github.com/Go-Server/Utils"
	_ "github.com/lib/pq"
)

type DataBase struct {
	Database *sql.DB
	Dbconfig DatabaseConfig
}

type DatabaseConfig struct {
	host     string
	port     string
	user     string
	password string
	dbname   string
	sslmode  string // 是否采用SSL通信  sslmode=disable 表示否
}

// ref : https://www.cnblogs.com/songxingzhu/p/5024517.html
func (db *DataBase) Open(dbconfig DatabaseConfig) {
	psqlInfo := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
		dbconfig.host,
		dbconfig.port,
		dbconfig.user,
		dbconfig.password,
		dbconfig.dbname,
	)
	open, e := sql.Open("postgres", psqlInfo)
	Utils.CheckErr(e)
	db.Database = open
	db.Dbconfig = dbconfig
}

func (db *DataBase) CreatTable() {

}

func (db *DataBase) InsertData() {

}
